///
/// 用户信息
/// page用户信息
///

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:qgchat/common/class/videoCall/index.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/models/listuserInfoModel.dart';
import 'package:qgchat/states/states_model/index.dart';

class UserInfoDialog extends StatelessWidget {
  const UserInfoDialog({this.targetInfo, Key key}) : super(key: key);

  final ListuserInfoModel targetInfo;

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Stack(
        alignment: AlignmentDirectional.center,
        children: <Widget>[
          GestureDetector(
            onTapUp: (i) => Navigator.of(context).pop(),
          ),
          Stack(
            overflow: Overflow.visible,
            children: <Widget>[
              // 内容
              Container(
                width: px(690),
                height: px(370),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(
                    px(22),
                  ),
                  color: Colors.white,
                ),
                child: Column(
                  children: <Widget>[
                    // 顶部功能按钮
                    _ToolBar(targetInfo: targetInfo),
                    // 昵称
                    _NickName(targetInfo: targetInfo),
                    // 去私聊
                    _GoChatBtn(targetInfo: targetInfo),
                    // 用户数据
                    _Data(targetInfo: targetInfo),
                  ],
                ),
              ),
              // 头像
              _Avatar(targetInfo: targetInfo),
            ],
          )
        ],
      ),
    );
  }
}

/// 头像
class _Avatar extends StatelessWidget {
  const _Avatar({this.targetInfo, Key key}) : super(key: key);

  final ListuserInfoModel targetInfo;

  @override
  Widget build(BuildContext context) {
    return Positioned(
      top: -px(98),
      left: px(247),
      child: Container(
        width: px(196),
        height: px(196),
        decoration: BoxDecoration(
          border: Border.all(
            color: Colors.white,
            width: px(10),
          ),
          borderRadius: BorderRadius.circular(px(98)),
          image: DecorationImage(
            image: NetworkImage(
              "${targetInfo.memberHead}",
            ),
            fit: BoxFit.cover,
          ),
        ),
      ),
    );
  }
}

/// 顶部功能按钮
class _ToolBar extends StatelessWidget {
  const _ToolBar({this.targetInfo, Key key}) : super(key: key);

  final ListuserInfoModel targetInfo;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: px(70),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Container(),
          // Container(
          //   width: px(118),
          //   child: FlatButton(
          //     onPressed: () {
          //       showCupertinoModalPopup<int>(
          //         context: context,
          //         builder: (context) {
          //           return _Report();
          //         },
          //       );
          //     },
          //     padding: EdgeInsets.all(0),
          //     child: Row(
          //       mainAxisAlignment: MainAxisAlignment.center,
          //       children: <Widget>[
          //         Container(
          //           margin: EdgeInsets.only(right: px(9)),
          //           child: Icon(
          //             Icons.error_outline,
          //             color: col("bfc2cc"),
          //             size: px(30),
          //           ),
          //         ),
          //         Text(
          //           "举报",
          //           style: TextStyle(
          //             height: .99,
          //             color: col("bfc2cc"),
          //             fontSize: px(24),
          //           ),
          //         ),
          //       ],
          //     ),
          //   ),
          // ),
          IconButton(
            onPressed: () => Navigator.pop(context),
            padding: EdgeInsets.all(0),
            icon: Icon(
              Icons.clear,
              color: col("bfc2cc"),
            ),
          ),
        ],
      ),
    );
  }
}

/// 举报弹窗
class _Report extends StatelessWidget {
  const _Report({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CupertinoActionSheet(
      message: Text(
        '请选择举报类型',
        style: TextStyle(
          color: col("606266"),
          fontSize: px(26),
        ),
      ),
      cancelButton: CupertinoActionSheetAction(
        onPressed: () => Navigator.pop(context),
        child: Text(
          "取消",
          style: TextStyle(
            color: col("157efb"),
            fontSize: px(40),
          ),
        ),
      ),
      actions: <Widget>[
        CupertinoActionSheetAction(
          onPressed: () {
            showToast("举报成功，官方会马上核实");
            Navigator.pop(context, 1);
          },
          child: Text(
            '政治敏感',
            style: TextStyle(
              color: col("303133"),
              fontSize: px(40),
            ),
          ),
        ),
        CupertinoActionSheetAction(
          onPressed: () {
            showToast("举报成功，官方会马上核实");
            Navigator.pop(context, 2);
          },
          child: Text(
            '色情低俗',
            style: TextStyle(
              color: col("303133"),
              fontSize: px(40),
            ),
          ),
        ),
        CupertinoActionSheetAction(
          onPressed: () {
            showToast("举报成功，官方会马上核实");
            Navigator.pop(context, 3);
          },
          child: Text(
            '广告骚扰',
            style: TextStyle(
              color: col("303133"),
              fontSize: px(40),
            ),
          ),
        ),
        CupertinoActionSheetAction(
          onPressed: () {
            showToast("举报成功，官方会马上核实");
            Navigator.pop(context, 3);
          },
          child: Text(
            '人身攻击',
            style: TextStyle(
              color: col("303133"),
              fontSize: px(40),
            ),
          ),
        ),
      ],
    );
  }
}

/// 昵称
class _NickName extends StatelessWidget {
  const _NickName({this.targetInfo, Key key}) : super(key: key);

  final ListuserInfoModel targetInfo;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: px(67)),
      child: Text(
        "${targetInfo.memberNickname}",
        style: TextStyle(
          height: .99,
          color: col("303133"),
          fontSize: px(38),
        ),
      ),
    );
  }
}

/// 用户数据
class _Data extends StatelessWidget {
  const _Data({this.targetInfo, Key key}) : super(key: key);

  final ListuserInfoModel targetInfo;

  @override
  Widget build(BuildContext context) {
    List<Widget> list = [
      Container(
        width: px(210),
        height: px(70),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Text(
              "${targetInfo.money}",
              style: TextStyle(
                height: .95,
                color: col("303133"),
                fontSize: px(34),
                fontWeight: FontWeight.bold,
              ),
            ),
            Text(
              "余额",
              style: TextStyle(
                height: .95,
                color: col("909399"),
                fontSize: px(26),
              ),
            ),
          ],
        ),
      ),
      Container(
        width: 1,
        height: px(50),
        color: col("edeff2"),
      ),
      Container(
        width: px(210),
        height: px(70),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Text(
              "${targetInfo.gold2}",
              style: TextStyle(
                height: .95,
                color: col("303133"),
                fontSize: px(34),
                fontWeight: FontWeight.bold,
              ),
            ),
            Text(
              "总消费",
              style: TextStyle(
                height: .95,
                color: col("909399"),
                fontSize: px(26),
              ),
            ),
          ],
        ),
      ),
    ];
    if (targetInfo.gold1 != null && targetInfo.gold1 > 0) {
      list.add(Container(
        width: 1,
        height: px(50),
        color: col("edeff2"),
      ));
      list.add(Container(
        width: px(210),
        height: px(70),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Text(
              "${targetInfo.gold1}",
              style: TextStyle(
                height: .95,
                color: col("303133"),
                fontSize: px(34),
                fontWeight: FontWeight.bold,
              ),
            ),
            Text(
              "为我消费",
              style: TextStyle(
                height: .95,
                color: col("909399"),
                fontSize: px(26),
              ),
            ),
          ],
        ),
      ));
    }

    return Container(
      margin: EdgeInsets.only(top: px(35)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: list,
      ),
    );
  }
}

class _GoChatBtn extends StatelessWidget {
  const _GoChatBtn({this.targetInfo, Key key}) : super(key: key);

  final ListuserInfoModel targetInfo;

  @override
  Widget build(BuildContext context) {
    UserState user = state(context, 'user');
    if (user.info.memberType == 1) {
      return Container(
        width: px(84),
        height: px(40),
        margin: EdgeInsets.only(top: px(20)),
        child: OutlineButton(
          onPressed: () {
            VideoCall.checkUserStatusAndGoChatPage(
                context, targetInfo.memberToken);
          },
          padding: EdgeInsets.zero,
          borderSide: BorderSide(color: col("6f53ff")),
          child: Text(
            "私信",
            style: TextStyle(
              color: col("5640c6"),
              fontSize: px(24),
            ),
          ),
        ),
      );
    } else {
      return Container();
    }
  }
}
